<template>
	<view class="warp">
		<view class="mdol">
			<view v-for="item in shopIfo" style="background:#fff;margin-top:30rpx;padding: 20rpx">
				<view style="width:100%;height:200upx;display:flex;align-items: center;">
					<view style="width:200upx">
						<u-upload :fileList="fileList" @afterRead="afterRead($event,item)" imageMode="scaleToFill" name="1" :maxCount="1"
							previewImage class="uimg">
							<view v-if="item.shopLogo">
								<image :src="imgpath+item.shopLogo" class="dplogo"/>
							</view>
							<view v-else>
							  <image :src="logo" class="dplogo"></image>
							</view>
						</u-upload>
					</view>
					<view>
						<view style="width:100%;font-size: 1.2rem;font-weight: bold;">{{item.shopName}}</view>
						<view>
							<u-switch @change="onShopState" size="20" v-model="item.openFlag==1?true:false" activeColor="#F66B71"
								inactiveColor="#ffffff"></u-switch>
						</view>
					</view>
				</view>
				<u-row>
					<u-col span="6">
						<view>店铺地址：{{item.shopAdd}}</view>
						<view>{{item.openTime}}~{{item.closeTime}}</view>
					</u-col>
					<u-col span="6" >
						<view style="display: flex;flex-wrap: wrap;justify-content: space-around;line-height: 30px;">
							<u-button @click="goPages(1,item)" :customStyle="cusbtncss"  type="primary" icon="photo"  size="mini" text="商品信息"></u-button>
							<u-button @click="goPages(2,item)"  type="success" icon="volume" :customStyle="cusbtncss"  size="mini" text="店铺公告"></u-button>
							<u-button @click="goPages(3,item)"  type="error" icon="gift" :customStyle="cusbtncss" size="mini" text="店铺活动"></u-button>
							<u-button @click="goPages(4,item)" type="warning" icon="edit-pen" :customStyle="cusbtncss" size="mini" text="店铺评论"></u-button>
						</view>
					</u-col>
				</u-row>
			</view>
		</view>
	</view>
</template>

<script>
	import Config from '@/util/index.js'
	import {
	 getShopIfoBytel,editShopLogo
	} from '@/api/goods'
	export default {
		data() {
			return {
				fileList: [],
				pagenum: 0,
				pagesize: 10,
				imgpath: '',
				userlogo:'',
				logo:'',
				noNotice: false,
				shopState: false,
				cusbtncss:{
					width:"80px",
					marginTop:"10px"
				},
				options2: [{
					text: '修改',
					style: {
						backgroundColor: '#3c9cff'
					}
				}, {
					text: '删除',
					style: {
						backgroundColor: '#f56c6c'
					}
				}],
				shopIfo:[],
			}
		},
		created(){
			uni.showLoading({
				title: '加载中...'
			})
			this.imgpath = Config.get('apiUrl')
			this.logo = this.picUrl + "logo.png"
			this.getStoreInfo()
		},
		methods: {
			goPages(type,item){
				console.log("itemm",item)
				if(type==1){
					uni.navigateTo({
						url: `manage/goods/index?shopid=${item.shopId}&rcode=${item.deptId}&shopname=${item.shopName}`
					})
				}else if(type==2){
					uni.navigateTo({
						url: `manage/goods/notice?rcode=${item.shopId}`
					})
				}else if(type==3){
					uni.navigateTo({
						url: `manage/active?rcode=${item.shopId}`
					})
				}else{
					uni.navigateTo({
						url: `manage/comment?rcode=${item.shopId}`
					})
				}
			},
			beforeRead(event) {
				const {
					file,
					callback
				} = event.file;
				callback(file.type === 'image');
			},
			afterRead(event,item) {
				let file = event.file;
				// 当设置 mutiple 为 true 时, file 为数组格式，否则为对象格式
				let _this = this
				uni.uploadFile({
					url: _this.imgpath + '/common/upload',
					filePath: file.url,
					name: 'file',
					success(res) {
						let logoImg = JSON.parse(res.data)
						_this.userlogo = _this.imgpath + logoImg
						item.shopLogo = logoImg.fileName
						_this.fileList = []
						fileList.push({
							...file,
							url: logoImg.url
						});
						_this.fileList = fileList;
						console.log("item",item)
						editShopLogo(item).catch(resx => {
							console.log("1122",resx)
							// _this.getNoticeInfo()
							_this.getStoreInfo()
							uni.hideLoading()
						})
					}
			    });
			},
			onShopState(e) {
				this.shopState = e
				let state = this.shopState ? '1' : '0'
				this.shopStateSwitch(state)
			},
			
			shopStateSwitch(value) {
				let params = {
					mid: uni.getStorageSync('loginInfo').mid,
					openflag: value
				}
				// Api.shopSwitch(params).then(res => {
				// 	if (res.retCode == 0) {
				// 		if (value == 1) {
				// 			uni.showToast({
				// 				title: '已开通营业',
				// 				icon: 'none',
				// 				duration: 2000
				// 			});
				// 		} else {
				// 			uni.showToast({
				// 				title: '已关闭营业',
				// 				icon: 'none',
				// 				duration: 2000
				// 			});
				// 		}
				// 	}
				// })
			},
			orderStateSwitch(value) {
				let params = {
					mid: uni.getStorageSync('loginInfo').mid,
					orderflag: value
				}
				// Api.changeOrder(params).then(res => {
				// 	if (res.retCode == 0) {
				// 		uni.showToast({
				// 			title: '已开通下单',
				// 			icon: 'none',
				// 			duration: 2000
				// 		});
				// 	} else {
				// 		uni.showToast({
				// 			title: '关闭下单',
				// 			icon: 'none',
				// 			duration: 2000
				// 		});
				// 	}
				// })
			},
			getStoreInfo() {
				let _this = this
				uni.getStorage({
					key: 'userifo',
					success: function (res) {
						if(res.data){
							let params = {
								userName:JSON.parse(res.data).userName
							}
							getShopIfoBytel(params).catch(res => {
								_this.shopIfo = res.data.rows
								// _this.getNoticeInfo()
								uni.hideLoading()
							})
						}
					}
				});
			},
			goEditstore() {
				uni.navigateTo({
					url: 'manage/edit?sifo=' + JSON.stringify(this.storeInfo),
				})
			},
			async delNotice(pid) {
				let params = {
					pid: pid
				}
				let _this = this
				const res = await showModel({
					content: '你确定要删除该公告吗？'
				});
				//在模态框中点击确认，删除购物车中的该商品数据
				if (res.confirm) {
					// Api.deteleNotice(params).then(res => {
					// 	if (res.retCode == 0) {
					// 		showToast({
					// 			title: "删除成功"
					// 		})
					// 		_this.getNoticeInfo()
					// 	} else {
					// 		console.log(res.info)
					// 	}
					// })
				} else {
					//取消删除
					//弹出提示取消删除
					await showToast({
						title: "取消删除"
					})
				}
			},
			goActivePage() {
				uni.navigateTo({
					url: 'manage/active?rcode=' + this.storeInfo.rcode,
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	.u-page {
		padding: 0;
	}
	.dplogo {
		width: 150rpx;
		height: 150rpx;
		margin: 20rpx auto;
	}
	.u-demo-block__title {
		padding: 10px 0 2px 15px;
	}

	.swipe-action {
		&__content {
			padding: 25rpx 0;

			&__text {
				font-size: 15px;
				color: $u-main-color;
				padding-left: 30rpx;
			}
		}
	}

	/* pages/manage/manageorder.wxss */
	.warp {
		width: 100%;
		margin: 10rpx auto;
		background: #f5f5f5
	}


	.dplb {
		display: flex;
		text-align: center;
		margin: 30rpx auto;
	}

	.dpcss {
		width: 100%;
		height: 150rpx;
		line-height: 150rpx;
		flex: 1;
		margin: 0rpx 20rpx;
		border-radius: 10px;
	}

	.u-swipe-cell__left,
	.u-swipe-cell__right {
		display: inline-block;
		width: 130rpx;
		height: 70rpx;
		font-size: 1rem;
		line-height: 90rpx;
		color: #fff;
		text-align: center;
		background-color: #F66B71;
	}

	.glcs {
		width: 100%;
		height: auto;
		background: #ffffff;
		padding-top: 10rpx;
		margin-top: 10rpx
	}

	.mdol {
		height: auto;
		line-height: 60rpx;
	}

	.dpxx {
		width: 100%;
		text-align: center;
		margin: 20rpx auto;
		line-height: 60rpx;
		font-size: 1rem
	}

	.dpkg {
		display: flex;
		align-items: left;
		justify-content: left;
		height: 70rpx;
		line-height: 70rpx;
		text-align: left;
	}
	.uimg{width:150rpx;height:150rpx;}
	.havegg {
		display: flex;
		width: 100%;
		height: 70rpx;
		line-height: 70rpx;
		border-bottom: 1px solid #f5f5f5;
	}

	.dpgg {
		height: auto;
		background: #ffffff;
		margin-top: 10rpx;
		background: #ffffff;
		padding: 0rpx 20rpx;
		line-height: 60rpx;
	}
</style>
